﻿using HomeWork911.Api.Read.Appliaction.Commond;
using HomeWork911.Api.Read.Dto;
using HomeWork911.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace HomeWork911.Api.Read.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class QueryController : ControllerBase
    {
        IMediator mediator;
        ILogger<ManualResetEvent> logger;

        public QueryController(IMediator mediator, ILogger<ManualResetEvent> logger)
        {
            this.mediator = mediator;
            this.logger = logger;
        }
        /// <summary>
        /// 用户登录
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回登录请求</returns>
        [HttpPost]
        public Task<ApiResult<LoginDto>> UserLogin(LoginCommond request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 展示用户信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回显示请求</returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<LoginDto>>> UserShow([FromQuery]ShowUserCommond request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 查看权限信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回查看请求</returns>
        [HttpGet]
        public Task<ApiResult<ApiPaging<ShowPermissionDto>>> ShowPermission([FromQuery] ShowPermissionCommond request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 反添权限信息
        /// </summary>
        /// <param name="request">请求</param>
        /// <returns>返回反添信息</returns>
        [HttpGet]
        public Task<ApiResult<List<ShowPermissionDto>>> Handle([FromQuery]GetPermissionCommond request)
        {
            GetPermissionCommond commond=new GetPermissionCommond();
            commond.PermissionId = request.PermissionId;
            return mediator.Send(request);
        }
    }
}
